/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function TableMachine(myparent, refreshInterval){
    this.parents = myparent;
    this.refreshInterval = refreshInterval;
    this.machines = new Array();
    this.loadObject = function(json){
        $(this.parents).html("");
        this.machines = new Array();
        for(var i=0; i < json.length;i++){
            var machine = json[i];
            var jMachine = new Machine("","",0,0);
            jMachine.loadJson(machine);
            this.machines.push(jMachine);
        }
    };
    this.generateTable = function(){
        $(this.parents).html("");
        var table = $("<table>",{
            class : "ui-widget ui-widget-content"
        });
        var header = $("<thead>");
        header.append(this.generateHeader());
        table.append(header);
        var body = $("<tbody>")
        for(var i = 0 ; i <this.machines.length; i++){
            var machine = this.machines[i];
            body.append(this.generateMachine(machine));
        }
        table.append(body)
        var footer = $("<tfoot>");
        footer.append(this.generateHeader());
        table.append(footer);
        var button = $("<button>",{
            text : "Ajouter une machine",
            click : function(){
                $("#dialog-form-machine").dialog("open");
            }
        });
        $(this.parents).append(button);
        $(this.parents).append(table);
    }
    this.generateHeader = function(){
        var element = $("<tr>",{
            class : "ui-widget-header"
        });
        var salle = $("<td>",{
            text : "Salle",
        });
        var ip = $("<td>",{
            text : "Ip",
        });
        var ram = $("<td>",{
            text : "Ram"
        });
        var disk = $("<td>",{
            text : "Disque"
        });
        var link = $("<td>",{
            text : "Détails"
        });
        element.append(salle);
        element.append(ip);
        element.append(ram);
        element.append(disk);
        element.append(link);
        return element;
    }
    this.generateMachine = function(machine){
        var element = $("<tr>",{
//            class : "table-machine"
        });
        var salle = $("<td>",{
            text : machine.getSalle(),
        });
        var ip = $("<td>",{
            text : machine.getIpAddress(),
        });
        var ram = $("<td>",{
            text : machine.getRam()
        });
        var disk = $("<td>",{
            text : machine.getDisk()
        });
        var link = $("<td>",{
        });
        var a = $("<a>",{
            text: 'Lien',
            title: 'Voir/Modifier',
            href: '#',
            click: function(){ 
                
            }
        });
        link.append(a);
        element.append(salle);
        element.append(ip);
        element.append(ram);
        element.append(disk);
        element.append(link);
        
        return element;
    };
}